<?php
namespace Crm\Domain;

use Crm\Common\MetaData as MetaData;
use Carbon\Carbon;

class Article
{
    /**
     * pdo连接。
     *
     * @var object
     * @access pdo
     */
    public $pdo;

    public $metaData;
    public $baseCode;
    public $scoreOption;//积分规则配置


    public function __construct()
    {
        $this->pdo = \PhalApi\DI()->pdo;
        $this->baseCode = (object)\PhalApi\DI()->config->get('basecode');
        $this->metaData = new MetaData();
        $this->scoreOption = $this->metaData->getPairBaseCodeByType(20203);
        //print_r($this->scoreOption);
    }

    /* 验证用户是否阅读该文章 */
    public function checkRead($user_id,$article_id){
        $sql = "select count(*) as cnt from wx_user_score where create_uid={$user_id} and type=2020305 and action_id={$article_id}";
        $rlt = $this->pdo->getRow($sql);
        if($rlt['cnt']>0){
            return true;
        }else{
            return false;
        }
    }

    /* 文章阅读统计 */
    public function hitSum($cid){
        $sql = "select sum(hits) as cnt from web_contentindex where cid=$cid and flag=1";
        $sum = $this->pdo->getRow($sql);
        return $sum['cnt'];
    }

    /* 文章阅读统计 */
    public function shareSum($cid){
        $sql = "select sum(shares) as cnt from web_contentindex where cid=$cid and flag=1";
        $sum = $this->pdo->getRow($sql);
        return $sum['cnt'];
    }

    /* 更新浏览量 */
    public function hitNum($id){
        $rlt = $this->pdo->doSql("update ".DB_PREFIX_WEB."contentindex set hits=hits+1 where id={$id}");
        return $rlt;
    }

    /* 更新浏览量 */
    public function shareNum($id){
        $rlt = $this->pdo->doSql("update ".DB_PREFIX_WEB."contentindex set shares=shares+1 where id={$id}");
        return $rlt;
    }

}

